import React, { Component } from 'react';
import FilterGroup from '../../components/filter-group';
import Counter from '../../components/counter';
import { getTableData } from '../../api/table';
import { Table } from 'antd';
import '../../App.css';

// btnIndex
// CONF
export default function (CONF, btnIndex) {

    return class BasePage extends Component {

        state = {
            data: [], // 这东西应该出现在model层  而不是这
        };
        
        componentDidMount () {
            CONF.BTNS[btnIndex].props.onClick = this.onSearch.bind(this);
            this.onSearch({});
        }
        
        async onSearch (params) {
            const data = await getTableData(params);
            this.setState({ data });
        }
        
        render () {
            return (
            <>
                <FilterGroup
                filters={ CONF.FILTERS }
                btns={ CONF.BTNS }
                />
                <Table 
                dataSource={ this.state.data } 
                columns={ CONF.COLUMNS }
                />
                <Counter />
            </>
            );
        }
        
    }
      
}
